'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

''' <summary>
''' Represents a property value fixup.
''' </summary>
Public Class PropertyValueFixUp
    Implements IFixUp

    Private ReadOnly _ReferencedValueId As Integer
    Private ReadOnly _PropertyDescriptor As PropertyDescriptor
    Private ReadOnly _Graph As Object

    Public Sub New(ByVal valueId As Integer, ByVal descriptor As PropertyDescriptor, ByVal graph As Object)
        _ReferencedValueId = valueId
        _PropertyDescriptor = descriptor
        _Graph = graph
    End Sub

    ''' <summary>
    ''' Gets the Id of the referenced value.
    ''' </summary>
    Public ReadOnly Property ReferencedValueId() As Integer
        Get
            Return _ReferencedValueId
        End Get
    End Property


    ''' <summary>
    ''' Gets the PropertyDescriptor for the Property which needs FixUp.
    ''' </summary>
    Public ReadOnly Property PropertyDescriptor() As PropertyDescriptor
        Get
            Return _PropertyDescriptor
        End Get
    End Property


    ''' <summary>
    ''' Gets the object graph which hosts the Property.
    ''' </summary>
    Public ReadOnly Property Graph() As Object
        Get
            Return _Graph
        End Get
    End Property

    Public Sub Execute(ByVal serializer As ISerializer) Implements IFixUp.Execute
        Dim value As Object = serializer.GetDeserializeObjectById(ReferencedValueId)

        PropertyDescriptor.SetValue(Graph, value)
    End Sub
End Class